﻿/*
 * 
 * User: Gavin Mead
 * Date: 11/25/2009
 * Time: 1:44 PM
 * 
 * 
 */

using System;
using NUnit.Framework;

using GraphLibrary;

namespace GraphLibraryTests
{
    [TestFixture]
    public class BaseEdgeTests
    {
        [Test]
        [Description("Verifies exception is thrown when either " +
                     "IVertexIds in constructor are null.")]
        public void NullVertexIdsTest()
        {
            ArgumentNullException ex1 = Assert.Throws<ArgumentNullException>(delegate {
                                                                                 IEdge<int> e = new BaseEdge<int>(null, null);
                                                                             });
            
            ArgumentNullException ex2 = Assert.Throws<ArgumentNullException>(delegate {
                                                                                 IEdge<int> e = new BaseEdge<int>(new BaseVertexId(),
                                                                                                                  null);
                                                                             });
            
            ArgumentNullException ex3 = Assert.Throws<ArgumentNullException>(delegate {
                                                                                 IEdge<int> e = new BaseEdge<int>(null,
                                                                                                                  new BaseVertexId());
                                                                             });
            
            Assert.NotNull(ex1);
            Assert.NotNull(ex2);
            Assert.NotNull(ex3);
        }
        
        
        [Test]
        [Description("Verifies that IEdgeId references the provided IVertexIds")]
        public void VertexIdReferenceTest()
        {
            IVertexId id1 = new BaseVertexId();
            IVertexId id2 = new BaseVertexId();
            
            IEdge<int> e = new BaseEdge<int>(id1, id2);
            
            Assert.AreEqual(id1, e.EdgeId.Vertex1Id);
            Assert.AreEqual(id2, e.EdgeId.Vertex2Id);
        }
        
        [Test]
        [Description("Verifies that the IEdge Data property sets and gets correctly")]
        public void EdgeDataPropertyTest()
        {
            IVertexId id1 = new BaseVertexId();
            IVertexId id2 = new BaseVertexId();
            
            IEdge<int> e = new BaseEdge<int>(id1, id2);
            
            Assert.AreEqual(id1, e.EdgeId.Vertex1Id);
            Assert.AreEqual(id2, e.EdgeId.Vertex2Id);
            
            e.EdgeData = 25;
            
            Assert.AreEqual(25, e.EdgeData);
        }
        
        [Test]
        [Description("Verifies that false is returned when performing an " +
                     "Equals() on two different IEdge<U>")]
        public void IEdgeInEqualityTest()
        {
            IVertexId id1 = new BaseVertexId();
            IVertexId id2 = new BaseVertexId();
            
            IEdge<int> e = new BaseEdge<int>(id1, id2);
            
            IVertexId id3 = new BaseVertexId();
            IVertexId id4 = new BaseVertexId();
            
            IEdge<int> e1 = new BaseEdge<int>(id3, id4);
            
            Assert.False(e.Equals(e1));
            Assert.False(e1.Equals(e));
        }
    }
}
